import hx.gemo.Point;
import hx.display.Graphics;
import hx.display.Stage;

class GameStage extends Stage {
	override function onStageInit() {
		super.onStageInit();
		// 代码开始的地方...
		// 图形绘制
		var graphics = new Graphics();
		graphics.beginFill(0xff0000);
		graphics.drawRect(0, 0, 100, 100);
		this.addChild(graphics);
		graphics.x = 100;
		graphics.y = 100;

		// 线段绘制
		var lineGraphics = new Graphics();
		lineGraphics.beginLineStyle(0x00ff00, 2);
		lineGraphics.moveTo(0, 0);
		lineGraphics.lineTo(100, 100);
		lineGraphics.lineTo(200, 0);
		lineGraphics.lineTo(300, 100);
		lineGraphics.lineTo(400, 0);
		this.addChild(lineGraphics);
		lineGraphics.x = 100;
		lineGraphics.y = 400;

		// 线段绘制五角星
		var starGraphics = new Graphics();
		starGraphics.beginLineStyle(0x0000ff, 10);
		// 绘制五角星
		var r = Math.PI * 2 / 5;
		var len = 200;
		var pos:Array<Point> = [];
		for (i in 0...5) {
			pos.push(new Point(Math.cos(r * i) * len, Math.sin(r * i) * len));
		}
		var start = pos.shift();
		// 调整为五角星绘制循序
		var startPos = [pos[1], pos[3], pos[0], pos[2]];
		starGraphics.moveTo(start.x, start.y);
		for (point in startPos) {
			starGraphics.lineTo(point.x, point.y);
		}
		starGraphics.lineTo(start.x, start.y);
		this.addChild(starGraphics);
		starGraphics.x = 500;
		starGraphics.y = 300;
	}
}
